<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="css/style.css" />
		<script type="text/javascript" src="js/js.js" ></script>
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js"></script> 
		<script type="text/javascript" src="laydate/laydate.js" ></script>
		<script>
		$(function(){
			getTaskno();
		});
		function select_file(){
		    $("#file").trigger("click");
		}
		function fileUpload(){
			var ext = $('#file').val();
			if (ext && /(jpg|png|bmp|jpeg|gif)$/.test(ext.toLowerCase())){
				$('#pic').append("&nbsp;&nbsp;&nbsp;"+$('#file').val());
            } else {  
                alert("请上传格式为 jpg|png|bmp|jpeg|gif 的图片！");  
            }
		}
		function getTaskno() {
			$.ajax({
				url : '../TasknoAutoServlet',
				type : 'POST',
				dataType : 'text',
				success : function(taskno) {
					$('#taskno').val(taskno);
				}
			});
		}
		function uploadInfo(){
			tag = false;
			$('input').each(function(){
				if (this.value==null || this.value==""){
					if ($(this).attr("id")=="file"){
						alert("请添加商品图片！");
						tag = true;
						$("#file").trigger("click");
						return false;
					}
					this.focus();
					alert("请输入完整信息！");
					tag = true;
					return false;
				}
			});
			if (tag)
				return;
		    var animateimg = $("#file").val(); //获取上传的图片名 带//  
		    var imgarr=animateimg.split('\\'); //分割  
		    var myimg=imgarr[imgarr.length-1]; //去掉 // 获取图片名  
		    var houzui = myimg.lastIndexOf('.'); //获取 . 出现的位置  
		    var ext = myimg.substring(houzui, myimg.length).toUpperCase();  //切割 . 获取文件后缀  
		      
		    var file = $('#file').get(0).files[0]; //获取上传的文件  
		    var fileSize = file.size;           //获取上传的文件大小  
		    var maxSize = 1048576;              //最大1MB  
			if (ext != '.PNG' && ext != '.GIF' && ext != '.JPG'
					&& ext != '.JPEG' && ext != '.BMP') {
				parent.layer.msg('文件类型错误,请上传图片类型');
			} else if (parseInt(fileSize) >= parseInt(maxSize)) {
				parent.layer.msg('上传的文件不能超过1MB');
				return false;
			} else {
				var data = new FormData($('#signupListImportForm')[0]);
				data.append("operation", "add");
				$.ajax({
					url : "../TaskOperationServlet",
					type : 'POST',
					data : data,
					dataType : 'JSON',
					cache : false,
					processData : false,
					contentType : false,
					success : function(json) {
						alert(json.message);
						location="orders.html";
					}
				});
			}
		}
		</script>
	</head>
	<body>
		<div class="main border-bottom-gray"><span class="fontBold"><a href="" class="mapsite">首页</a></span>&nbsp;/&nbsp;
			<span class="fontBold"><a href="" class="mapsite">订单信息</a></span>&nbsp;/&nbsp;添加订单</div>
		<form onsubmit="" id="signupListImportForm" class="import-file-form" enctype="multipart/form-data">
			<div class="title main">添加订单</div> 
			<div class="main fl wid600">
				<div class="padding10_0">订单编号:</div>
				<input id="taskno" name="taskno" type="text" class="input_text_long" placeholder="请输入订单编号" required/>
				<!-- <div class="padding10_0">收件人:</div>
				<input name="addressee" type="text" class="input_text_long" placeholder="请输入收件人" required/>
				 --><div class="padding10_0" id="pic">商品图片:</div>
				<input type="file" name="file" id="file" accept=".jpg,.png,.bmp,.jpeg,.gif" onchange="fileUpload()" style="display:none">
				<input type="button"  onclick="select_file()" value="添加图片" class="input_submit"> 
				<img id="fileImg" src="" style="display:none;" /><br/><br/>
				<div class="userid">用户姓名:</div>
				<input name="username" type="text" class="input_text_long" placeholder="请输入用户姓名" required/>
				<!-- <div class="padding10_0">订单付款状态:</div>
				<select name="payStatus" class="input_text">
					<option value="1">未付款</option>
					<option value="2">已付款</option>
					<option value="3">已退款</option>
				</select>
				 --><div class="padding10_0">商品名称:</div>
				<input name="goodsname" type="text" class="input_text_long" placeholder="请输入商品名称" required/>
				<div class="padding10_0">商品品牌:</div>
				<input name="brand" type="text" class="input_text_long" placeholder="请输入商品品牌" required/>
				<div class="padding10_0">商品类型:</div>
				<input name="type" type="text" class="input_text_long" placeholder="请输入商品类型" required/>
				<div class="padding10_0">商品原价:</div>
				<input name="price" type="text" class="input_text_long" placeholder="请输入商品原价" required/>
			</div>
			<div class="main fl wid600">
				<div class="padding10_0">商品颜色:</div>
				<input name="color" type="text" class="input_text_long" placeholder="请输入商品颜色" required/>
				<div class="padding10_0">商品尺码:</div>
				<input name="size" type="text" class="input_text_long" placeholder="请输入商品尺码" required/>
				<div class="padding10_0">商品数量:</div>
				<input name="goodsNumber" type="text" class="input_text_long" placeholder="请输入商品数量" required/>
				<div class="padding10_0">商品价格:</div>
				<input name="taskprice" type="text" class="input_text_long" placeholder="请输入商品数量" required/>
				<div class="padding10_0">国际运费:</div>
				<input name="freight" type="text" class="input_text_long" placeholder="请输入国际运费" required/>
				<div class="padding10_0" style="display:none" >总价:</div>
				<input name="totalPrice" style="display:none" value="0" type="text" class="input_text_long" placeholder="请输入总价" required/>
				<div class="padding10_0">付款编号:</div>
				<input name="payNo" type="text" class="input_text_long" placeholder="请输入付款编号" required/>
				<div class="padding10_0">下单时间:</div>
				<input id="time" name="time" type="text" class="input_text_long" placeholder="请输下单时间" required/>
				<div class="padding10_0 mt29">
					<input type="button" onclick="uploadInfo()" value="添加" class="input_submit"/>
					<input type="button" class="whitebutton" value="返回" onclick="history.back()"/>
				</div>
			</div>
			<div class="clear"></div>
		</form>
		<script>
			laydate.render({
			  elem: '#time'
			});
		</script>
	</body>
</html>
